//品牌管理
$(function(){
	$('#taskList').getList({
		"initData":{
			"num":1,
			"size":10,
			"qurtyType":3
		},
		"url":site.apiUrl+"/back/task/selectTimedTaskBackList",// 数据请求url
		"type":"POST",
		"checkname":"datachk", //选择器名称，为空不显示选择器
		"checkattr": [ //选择器上增加自定义属性，以便传递多个参数
      { "attr": "timedTaskId", "value": "{{timedTaskId}}" },
    ],
		"col":[  //数据列
			{"field":"taskName","display":"任务名称","width":"1.5"},
			{"field":"taskTypeDisplay","display":"任务类型","width":"1.5"},
			{"field":"taskLevelDisplay","display":"任务级别","width":"1.5"},
			{"field":"taskCategoriesDisplay","display":"任务类别","width":"1.5"},
			{"field":"pubWeekStr","display":"发布周期","width":"1.5"},
			{"field":"pubTime","display":"发布时间"},
			{"field":"publisher","display":"发布人","width":"1.5"},
			{"field":"enabledDisplay","display":"启用状态","width":"1.5"}
		],
		"option":[ //操作按钮配置view
			{"icon":"edit","tip":"查看","fun":"brandView('{{timedTaskId}}')"},  //icon: view,edit,add,del
			{"icon":"view","tip":"发布明细","fun":"newPage('{{timedTaskId}}')"},  // 花括号内可以对应相关字段
			{"icon":"del","tip":"删除","fun":"deleteBrand('{{timedTaskId}}')"}
		]
	});
	
	$("#taskType").getSelect({
		type:"screen",
		label:"任务类型：",
		asName:"taskType",
		code:"taskType",
	},function(){
		$('#taskType').find('input[value="3"]').parents("li").hide();
	});
	$("#taskLevel").getSelect({
		type:"screen",
		label:"任务级别：",
		asName:"taskLevel",
		code:"taskLevel"
	});
	$("#taskCategories").getSelect({
		type:"screen",
		label:"任务类别：",
		asName:"taskCategories",
		code:"taskCategories"
	});
	
	userList();
	departmentList();

	//批量删除
	$("#batchDelBtn").click(function(){
		var c = "";
		$("input[name=datachk]:checked").each(function(){
			c += $(this).attr('timedtaskid')+',';
		});
		if(c!= null && c!=''){
			deleteBrand(c);
		}else{
			ly.toast("请选择删除项");
		}
	});

});
//编辑
function brandView(id){
	ly.goto("new-task-creat.html?timedTaskId="+id+"&attendanceType=2")
}
function newPage(id) {
	ly.goto("new-task-creat-list.html?timedTaskId="+id+"")
}
function departmentList(){
	var urls =''+site.gateUrl+'/back/team/selectTeamList'
	request({
		url:urls ,
		data:{
			"num":1,
			"size":30,
		},
		ajaxform:true,
		type: 'get',
		callback: function(r) {
			if(r.code=="rest.success"){
				 var lists = r.result.list;
				 var htmls = '';
				 for (let i = 0; i < lists.length; i++) {
						htmls+='<option value="'+lists[i].id+'">'+lists[i].teamName+'</option>'
				 }
				 $('#departmentList').append(htmls)
			}else{

			}
			// ly.toast('密码重置成功');
			// ly.toast(r.msg);
		}
	});
}
function userList(){
	 var urls= site.gateUrl+'/sUsers/selectUsersList'
	 request({
		url:urls,
		data:{
			"num":1,
			"size":30,
		},
		type:"get",
		'ajaxform':true,
		callback:function(f) {
			var htmls = '';
			var datas= f.result.list;
			if(f.code=="rest.success"){
				for (let i = 0; i < datas.length; i++) {
						htmls+="<option value='"+datas[i].id+"'>"+datas[i].nickName+"</option>"
					}
					$("#userList").append(htmls)
			}else{
				ly.toast(f.desc);
			}
		}
	});
}
//删除
function deleteBrand(id){
	var url = site.gateUrl+"/back/task/deleteTimingTaskParameterByIdOnBack";
	ly.confirm("你确认删除吗？",function(){
		request({
			url:url,
			data:{"ids":id},
			type:"get",
			'ajaxform':true,
			callback:function(f) {
				if(f.code=="rest.success"){
					ly.toast("删除成功");
					$("#taskList").getList.refresh();//刷新当前分页
				}else{
					ly.toast(f.desc);
				}
			}
		});	
	});
}